//* Copyright(C) 2005-2012, all rights reserved.
//*
//* The following code is copyrighted and contains proprietary information
/* and trade secrets of Foxit Software Inc.      
**************************************************************************
*/

/**
* 工具栏插件类；
*/



define(function (require, exports, module) {
	
	FXREADER.RIBBON_STATUSBAR_PLUGIN_NAME = "StatusBar Ribbon Plugin";
	
    FXREADER.CRibbonStatusBarPlugin = function (pReaderApp) {
        var _pReaderApp = pReaderApp,
            _bInited = false,
            _Language = _pReaderApp.GetLanguage(),
             _self = this;

        var _RibbonDivID = _pReaderApp.GetBottomPanelID()+"_ribbon";
        var _BottomBarDivID = _RibbonDivID + "_bottombar";
        var _CenterBarDivID = _BottomBarDivID + "_center";
        var _RightBarDivID = _BottomBarDivID+ "_righttools";
        //获取Plugin名称;
        this.GetPluginName = function () {
            return FXREADER.RIBBON_STATUSBAR_PLUGIN_NAME;
        };

        //插件被注册的时候调用;
        this.PIOnRegister = function () {
            if (FXREADER.Config.ToolBar == null)
                return false;
            if (_bInited)
                return true;
            _self.CreateCmdAndCmdUI();
            var jqBottomPanel = $("#" + _pReaderApp.GetBottomPanelID());
            var ribbonPanelDiv = "<div id='"+_RibbonDivID+"' class='fwr_ribbon_bottom_panel' />";
            jqBottomPanel.append(ribbonPanelDiv);
            var jqRibbonDiv = $("#"+_RibbonDivID);
            var bottomDiv = "<div id='" + _BottomBarDivID + "' class='fwr_ribbon_bottombar'/>";
            jqRibbonDiv.append(bottomDiv);
           
            var jqBottomBar = $("#"+_BottomBarDivID);
            var centerDiv = "<span id='" + _CenterBarDivID + "' class='fwr_ribbon_bottombar_rowcenter' />";
            jqBottomBar.append(centerDiv);
            
            var rightToolBarDiv = "<span class='fwr_ribbon_bottombar_rowright' id='"+_RightBarDivID+"' />";
            jqBottomBar.append(rightToolBarDiv);
            
            jqBottomPanel.show();
           // jqTopPanel.append(_self.CreateToolBarHtml());
        };

        //模块初始化;
        this.PIInit = function () {
            if (FXREADER.Config.ToolBar == null)
                return false;
            if (_bInited)
                return true;
            _self.CreateToolBarHtml();
            _self.InitToolBarUI();
     //       _self.CreateCmdAndCmdUI();
          /*  var jqTopPanel = $("#" + _pReaderApp.GetTopPanelID());
            jqTopPanel.html("");
            jqTopPanel.append(_self.CreateToolBarHtml());
            _self.InitToolBarUI();

            $('.fwr_toolbar_btn').live('mousedown', function (event) {
                try {
                    if (event.button == 0 || event.button == 1) {
                        var cmdName = event.target.getAttribute("cmd");
                        _pReaderApp.ExecCommand(cmdName, null);
                    }
                }
                catch (ex) {
                }
            });
            _pReaderApp.OnResize();
            _pReaderApp.StepProgress();*/
            _bInited = true;
        };

        this.CreateToolBarHtml = function () {
        	
        	var centerTools = FXREADER.Config.RibbonStatusBar.center;
        	var centerToolsNum = centerTools.length;
        	var toolbarHtml = "";
        	for(var i = 0; i < centerToolsNum; i++)
        	{
        		 var btnName = centerTools[i];
                 var pCommandUI = _pReaderApp.GetCommandUI(btnName);
                 if (pCommandUI == null)
                     continue;
                 toolbarHtml += pCommandUI.CreateHtml();
        	}
        	 var jqCenterToolBar = $("#"+_CenterBarDivID);
        	 jqCenterToolBar.append(toolbarHtml);
        	 
        	 var rightTools = FXREADER.Config.RibbonStatusBar.right;
         	 var rightToolsNum = rightTools.length;
         	 var rightToolbarHtml = "";
         	 for(var i = 0; i < rightToolsNum; i++)
         	 {
         		 var btnName = rightTools[i];
                  var pCommandUI = _pReaderApp.GetCommandUI(btnName);
                  if (pCommandUI == null)
                      continue;
                  rightToolbarHtml += pCommandUI.CreateHtml();
         	 }
         	 var jqRightToolBar = $("#"+_RightBarDivID);
         	 jqRightToolBar.append(rightToolbarHtml);
        };
        
        this.InitToolBarUI = function () {
        	var centerTools = FXREADER.Config.RibbonStatusBar.center;
        	var centerToolsNum = centerTools.length;
        	for(var i = 0; i < centerToolsNum; i++)
        	{
        		 var btnName = centerTools[i];
                 var pCommandUI = _pReaderApp.GetCommandUI(btnName);
                 if (pCommandUI == null)
                     continue;
                 pCommandUI.Init();
        	}
        	
        	 var rightTools = FXREADER.Config.RibbonStatusBar.right;
         	 var rightToolsNum = rightTools.length;
         	 for(var i = 0; i < rightToolsNum; i++)
         	 {
         		 var btnName = rightTools[i];
                  var pCommandUI = _pReaderApp.GetCommandUI(btnName);
                  if (pCommandUI == null)
                      continue;
                  pCommandUI.Init();
         	 }
        };

        this.CreateCmdAndCmdUI = function () {
           
        };

     
        //模块卸载;
        this.PIUnload = function () {
        };

        this.GetReaderApp = function () {
            return _pReaderApp;
        };
    };

    exports.Reader_CreatePlugin = function (pReaderApp) {
        var pToolBarPlugin = new FXREADER.CRibbonStatusBarPlugin(pReaderApp);
        return pToolBarPlugin;
    };
});